Headless Server

Bonus notes on running a headless server.

Also see Terminal Tips section of this doc

Firstly, always aim to do everything through ssh terminal. It is tempting to add a GUI but it is unnecessary and costs memory and CPU. Even many web GUIs are inefficient and limited. The closest thing to a power-user server GUI is use of a tiling terminal multiplexer with mouse support -> sudo apt install tmux

tmux

A great way to access headless servers through CLI. First SSH into the server and install and run tmux. Quick start for beginners Good tmux tips
tmux prefix = Ctrl + b

ssh {server IP address} sudo apt install tmux

Install tmux plugin manager using instructions here

https://jdhao.github.io/2019/01/17/tmux_plugin_management/#install-tpm-

This is my config file with some nice defaults and plugins ~/.tmux.conf

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# .... maybe more plugins here

set -g mouse on

# Plugins and settings for session saving
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
set -g @continuum-save-interval '10'

# By default these programs are restored. Add more below.
# vi vim nvim emacs man less more tail top htop irssi weechat mutt
set -g @resurrect-processes 'mc nano glances iftop'
set -g @resurrect-capture-pane-contents 'on'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'

Select/copy/paste text in tmux session: Hold shift + drag to do this, including Shift + middle-mouse to paste.

Session save and restore:

Default autosave every 15 mins. Save: prefix + Ctrl-s Restore: prefix + Ctrl-r

Midnight Commander (CLI GUI file browser)

sudo apt install mc
mc -x

(-x enables mouse support)

VM Virtual Box

Enabling VMs to launch automatically at boot Virtualbox CLI management basics Full vboxmanage CLI reference

VBoxManage list vmsView list of VMs
VBoxManage showvminfo {vmname}View VM info
VBoxManage startvm {vmname} --type headlessStart VM
VBoxManage controlvm {vmname} acpipowerbuttonShutdown Safely

Modify network settings

VBoxManage modifyvm {vmname} --bridgeadapter1 {adapter-name}
VBoxManage modifyvm {vmname} --macaddress1 {mac-without-:'s}

Download, insert and install guest additions:

sudo apt-get install virtualbox-guest-additions-iso
VBoxManage storageattach {vmname} --storagectl IDE --device 0 --port 1 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso
VBoxManage storageattach {vmname} --storagectl IDE --device 0 --port 1 --medium none

Installing with LUKS encryption and automatically unlocking on boot with keyfile

https://dradisframework.com/support/guides/customization/auto-unlock-luks-encrypted-drive.html

(Note this will render the encryption more or less useless!)

Adding a swap file (Server doesn’t have one by default)

https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/

Transferring files between server

  • FTP
  • wormhole send

GUI CLI Docker

https://github.com/jesseduffield/lazydocker/blob/master/README.md

Advanced use of Git

https://learngitbranching.js.org/

What to back up

Nextcloud

https://github.com/nextcloud/nextcloud-snap/wiki/How-to-backup-your-instance

The best ways to install and deploy remote software

Canonical is pushing Snap, a package/deployment system which works well for both desktop and server apps. Dependencies are packaged together and run sandboxed via snapd, and directly share the system resources, peripherals, ip/network, including filesystem (as long as they are given the right permissions and read/write).

Manage Snap from CLI:

https://itsfoss.com/use-snap-packages-ubuntu-16-04/

Another popular alternative is Docker. Docker is a containerisation system which runs sandboxed apps and can be easily scaled to many instances dynamically based on load.

Change IP and DNS settings on command line:

Check settings:

systemd-resolve --status

Or equivalent: resolvectl

Change settings:

sudo nano /etc/netplan/00-installer-config.yaml

Add lines as described here

Run to refresh network settings and check:

sudo netplan apply

ip a

Remote GUI for Headless server

Many admins will discourage GUI use for servers, citing extra resource use and you can already do everything via the terminal if you bother to learn it.

If you have a server with average capability it can handle running a GUI just fine and personally I have come across a handful of situations where a GUI can really help out. One of these is administering a Virtual Box appliance hosted on the server.

The recommended GUI for a server is LXDE due to its low resource usage. It is very simple to install and enable for remote RDP access only. Here is a guide.

To connect remotely from another Ubuntu Desktop PC, you can use Remmina or similar. Once you have LXDE installed and setup, reboot the server and create an RDP connection to it an also enable SSH Tunnel in connection settings.